package top.zhangjianyong.blog.manage.controller;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.zhangjianyong.blog.annotation.Permission;
import top.zhangjianyong.blog.enums.RoleKeys;
import top.zhangjianyong.blog.params.user.*;
import top.zhangjianyong.blog.response.ApiResponse;
import top.zhangjianyong.blog.service.UserService;

/**
 * 用户管理类
 *
 * @author HDN
 * @since 2024/7/30 下午10:17
 */
@RequestMapping("/user/manage")
@RestController
@Permission(roles = {RoleKeys.ADMIN})
public class UserManageController {

  private final UserService userService;

  public UserManageController(UserService userService) {
    this.userService = userService;
  }

  /*分页查询*/
  @PostMapping("/page")
  public ApiResponse page(@RequestBody @Validated UserPageParam param) {
    return userService.page(param);
  }

  /*删除用户*/
  @PostMapping("/remove")
  public ApiResponse remove(@RequestBody @Validated UserDeleteParam param) {
    return userService.remove(param);
  }

  /*新增修改*/
  @PostMapping("/saveOrUpdate")
  public ApiResponse saveOrUpdate(@RequestBody @Validated UserSaveOrUpdateParam param) {
    return userService.saveOrUpdate(param);
  }

  /*查询用户角色*/
  @PostMapping("/roles")
  public ApiResponse roles(@RequestBody @Validated UserRolesParam param) {
    return userService.roles(param);
  }

  /*管理用户权限*/
  @PostMapping("/roles/update")
  public ApiResponse rolesUpdate(@RequestBody @Validated UserRolesUpdateParam param) {
    return userService.update(param);
  }
}
